// pages/login/index.js
import {
  studentPwdReset,
  teacherPwdReset
 } from "../../api/manage";

Page({
  data: {
    userType:'student',
    accountType:'学号',
    account:'',
    password:'',
    confirmPassword:''
  },

  onLoad: function(options) {
    this.setData({
      userType: options.userType|| 'student',
      accountType: options.userType === 'student' ? '学号' : '工号'
    });
  },

  onReset() {
    if(this.data.userType==='student'){
      studentPwdReset(this.data.account, this.data.password,this.data.confirmPassword).then(res => {
        wx.showToast({
          title: res.msg,
          icon:'none'
        });
        if(res.code===200){
          //回到首页
          wx.navigateBack({
            delta:1
          })
       }})
    }else{
      teacherPwdReset(this.data.account, this.data.password,this.data.confirmPassword).then(res => {
        wx.showToast({
          title: res.msg,
          icon:'none'
        });
        if(res.code===200){
          //回到首页
          wx.navigateBack({
            delta:1
          })
       }})
    }
  },

  inputAcc:function(e){
    this.setData({
      account: e.detail.value
    })
  },
  inputPwd:function(e){
    this.setData({
      password: e.detail.value
    })
  },
  inputConfirmPwd:function(e){
    this.setData({
      confirmPassword: e.detail.value
    })
  }
});
